home *** CD-ROM | disk | FTP | other *** search
/ MacHome 2001 June / MacHome Magazine Demo Disc June 2001.iso / Stuff / Software / Productivity / KnowledgeMiner 3.2.1 / AppleScript Support / missing values < prev    next >
Encoding:
Text File  |  2000-09-19  |  2.1 KB  |  68 lines  |  [TEXT/ToyS]

  1. tell application "KnowledgeMiner 3.2"
  2.     activate
  3.     
  4.     -- set start column
  5.     set startindex to index of column "b"
  6.     
  7.     -- set number of columns to calculate
  8.     set noOfColumns to 1
  9.     
  10.     if noOfColumns < 1 then
  11.         set noOfColumns to 1
  12.     end if
  13.     
  14.     repeat with j from startindex to startindex + noOfColumns - 1
  15.         try
  16.             -- set the last row; this works not in all cases, e.g., if the last row is a missing value
  17.             set lastrow to (rowIndex of last cell of column j whose kind is "valuecell")
  18.             try
  19.                 set temp to (rowIndex of second cell of column j whose kind is "textcell") - 1
  20.             on error
  21.                 set temp to lastrow
  22.             end try
  23.             
  24.             if temp < lastrow then
  25.                 set lastrow to temp
  26.             end if
  27.             
  28.             -- or set a fixed value
  29.             --set lastrow to myLastRow
  30.             
  31.             --get the last row of a column that is not empty; used for report
  32.             set reportrow to (rowIndex of last cell of column j whose kind is not "emptycell") + 2
  33.             
  34.             -- read all existing values of a column into the list x
  35.             set x to (value of every cell of column j whose kind is "valuecell" and rowIndex is less than or equal to lastrow)
  36.             
  37.             -- get the dimension of list x
  38.             set n to count x
  39.             
  40.             -- calculate the mean value
  41.             if n > 0 then
  42.                 set i to 0
  43.                 set mean to 0
  44.                 repeat n times
  45.                     set i to i + 1
  46.                     set u to item i of x
  47.                     set mean to u + mean
  48.                 end repeat
  49.                 set mean to mean / n
  50.             end if
  51.             
  52.             -- fill all missing values of a column with the column mean
  53.             set (value of every cell of column j whose (kind is "emptycell" and rowIndex is less than or equal to lastrow)) to mean
  54.             
  55.             -- report
  56.             set value of cell reportrow of column j to "mean"
  57.             set value of cell (reportrow + 1) of column j to mean
  58.             set value of cell (reportrow + 3) of column j to "# of filled cells"
  59.             set value of cell (reportrow + 4) of column j to (lastrow - n - 1)
  60.             set value of cell (reportrow + 5) of column j to "% filled"
  61.             set value of cell (reportrow + 6) of column j to (100 * (lastrow - n - 1) / (lastrow - 1))
  62.             
  63.         on error -- no missing values are found in column j
  64.             set value of cell (reportrow + 3) of column j to "# of filled cells"
  65.             set value of cell (reportrow + 4) of column j to 0
  66.         end try
  67.     end repeat
  68. end tell